import { pageTeacher } from '../../../api/user'

Page({
  data: {
    list: [],
    listQuery: {
      condition: {},
      pager: {
        page: 1,
        pageSize: 10
      }
    },
    isEnd: false
  },
  onLoad: function (options) {
    this.init()
  },
  init() {
    this.getMore()
  },
  getMore() {
    const _this = this
    pageTeacher(this.data.listQuery).then(res => {
      const list = JSON.parse(JSON.stringify(_this.data.list))
      if (res.length) {
        res.forEach(data => {
          list.push(data)
        })
      }
      this.setData({
        list: list
      })
      if (res.length < 10) {
        this.setData({ isEnd: true })
      }
    })
  },
  toLower() {
    if (!this.data.isEnd) {
      const page = this.data.listQuery.pager.page + 1
      this.setData({
        'listQuery.pager.page': page
      })
      this.getMore()
    }
  }
})
